Release 10.1A: OpenEdge Development:
Programming Interfaces
Reading data on a socket
To read data from a connected TCP/IP socket, you invoke the
READ( )method on the corresponding socket object (SELF:READ( )within the correspondingREAD-RESPONSEevent procedure). You can invoke this method on a connected socket at any time to read data. However, the method blocks depending on the amount of data available on the socket, the reading mode that you use, and the timeout value (set by theSO-RCVTIMEOoption of theSET-SOCKET-OPTION()method).The syntax of the
READ( )method follows:
The
READ( )method transfers data from the socket to the specifiedMEMPTRvariable,memptr-expression, at the byte position in theMEMPTRregion specified by theINTEGERexpression,position. Exactly how much data theREAD( )method blocks to read depends on:Specifying the read mode
You can specify
modeusing a compiler constant as shown in Table 17–3.
Thus, you can have the
READ( )method block until exactly the specified number of bytes are read (the default), or until all available bytes are read up to a maximum number allowed.The appropriate reading mode to use depends on your application requirements. Note, however, that if you specify
READ-EXACT-NUM, theREAD( )method blocks until it reads the specified number of bytes (no matter how long it takes) or until the socket is disconnected (whatever happens first).Specifying the timeout length
Besides setting the read mode, you can also set the amount of time
READ()waits before timing out. To do so, use theSO-RCVTIMEOoption of theSET-SOCKET-OPTION()method. If you do not set a timeout value, the default is forREAD()to wait forever.
READ()’s timeout behavior is affected by the interaction of the read mode and the timeout value, as Table 17–4 illustrates.
Verifying the number of bytes actually read
You can verify the number of bytes actually read by the
READ( )method. The number of bytes read by the lastREAD( )method invoked on a socket object is equal to the value of theBYTES-READattribute invoked on the same socket object.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |